<?php
declare(strict_types=1);
namespace App\ZxAdmin\Content\Album;
use App\Controller;
use Field\SysAlbumAttachConst;
use Field\SysAlbumAttachColumns;
use Field\SysAlbumAttachRow;
use Field\SysUserConst;
use Framework\Support\Upload;
use OSS\Core\OssException;
use OSS\OssClient;

// hook controller_zx_admin_content_album_sys_album_attach_use.php

/**
 * @title   附件管理
 * @auth    true
 * @login   true
 * @menu    true
 * @component   other/attach.vue
 * @icon    el-icon-menu
 * @active  true
 * @affix   false
 * @rank    99
 */
class SysAlbumAttach extends Controller
{
    // hook controller_zx_admin_content_album_sys_album_attach_public_start.php

    // make public SysAlbumAttach ZxAdmin\Content\Album
    /*
    protected array $echo_field 	=	[];
    protected array $edit_field	    =	[];
    protected array $add_field      =	[];
    protected array $field_fields_kv	=	[];
    protected array $Columns	    =	[];
    */
    public const make=1;
    /**
     * @title   列表配置
     */
    public const Conf=[
        'pageSize'=>25,
        'remoteSort'=>1,
        'remoteFilter'=>1,
        'remoteSummary'=>0,
        'hidePagination'=>1,
        'hideRefresh'=>1,
        'hideSetting'=>1,
        'hideDo'=>1,
        'add'=>1,
        'start'=>0,
        'stop'=>0,
        'delete'=>1,
        'import'=>0,
        'export'=>0
    ];
    /**
     * @title   列操作
     */
    public const Tools=[];
   /**
    * @title   列配置
    */
    public const Columns=[];
    /**
     * @title   筛选
     */
    public const Filter=[];
    /**
     * @title   添加内容
     */
    public const AddForm=[];
    /**
     * @title   编辑内容
     */
    public const EditForm=[];

    // hook controller_zx_admin_content_album_sys_album_attach_public_end.php
    /**
     * @title  下发配置
     * @rank    99
     */
    public function action_Conf()
    {
        // hook controller_zx_admin_content_album_sys_album_attach_conf_start.php

        $data=[];
        $Columns=[];
        foreach (self::Columns as $row){
            $Columns[]=$row;
        }
        /*

        $data['Column']=$this->Columns;
        $data['Tools'] = [];
        $Tools = [];
        foreach ($Tools as $k=> $row){
            switch ($row['do']){
                case 'add':
                case 'edit':
                case 'delete':
                case 'into':
                case 'start':
                case 'stop':
                    if($this->SysRoleAuth->Check($this->token->RoleID)){
                        $data['Tools'][]=$row;
                    }
                    break;
            }
        }
        */
        // make conf SysAlbumAttach ZxAdmin\Content\Album
        // hook controller_zx_admin_content_album_sys_album_attach_conf_end.php
        $this->response('0000', ['Conf' =>self::Conf,'Filter'=>self::Filter,'Tools'=>self::Tools,'Columns'=>$Columns,'data' =>$data]);
    }

    /**
     * @title   下发列表数据
     * @rank    99
     */
    public function action_Index()
    {
        // hook controller_zx_admin_content_album_sys_album_attach_index_start.php
        $page=$this->request->param('page', 0);
        $size=$this->request->param('limit', 10);
        $AlbumID=$this->request->param('AlbumID', []);
        $keyword=$this->request->param('keyword', '');
        $field = $this->request->param('field', '');
        $sort = $this->request->param('sort', '');
        $order=[];
        !empty($field) && $order[$field] = $sort=='asc'?-1:1;
        $cond = [];

        !empty($AlbumID) && $cond[SysAlbumAttachConst::AlbumID]=$AlbumID;
        !empty($keyword) && $cond[SysAlbumAttachConst::Name]['LIKE']=$keyword;
        $data = $this->SysAlbumAttach->GetList($cond,$order,$page,$size);

        // hook controller_zx_admin_content_album_sys_album_attach_index_end.php
        $this->response('0000', $data);
    }
    
    
    
    //need_delete_start
     /**
      * @title   删除数据
      */
    public function action_Index_Delete()
    {
        // hook controller_zx_admin_content_album_sys_album_attach_delete_start.php
        $data = $this->request->param('data',[]);
        $this->CheckEmpty([$data], ['操作数据为空']);
        $r = $this->SysAlbumAttach->deleteByIndex($data);
        // hook controller_zx_admin_content_album_sys_album_attach_delete_end.php
        $this->response($r?'0000':'0001', ['data' =>$r]);
    }
    //need_delete_end
    /**
     * @title   上传文件
     */
    public function action_Upload()
    {
       $AlbumID=$this->request->param('AlbumID', 1);
       $files = $this->request->getFiles();
       empty($files['file']) && $this->response('0003',[],'文件为空');
       $res = Upload::upload_file($files['file'],$this->token->UserID.'_'.unid(),1024);
       $this->SysAlbumAttach->insert(['AlbumID'=>$AlbumID,'Name'=>$res['Name'],'Patch'=>$res['Patch'],'TypeID'=>1,'Spec'=>$res['Spec'],'Ext'=>$res['Ext'],'UserID'=>$this->token->UserID]);
       $this->response('0000',['data'=>$res]);
    }

    // hook controller_zx_admin_content_album_sys_album_attach_end.php
}
?>